package cn.com.code.generator.base.vo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lvshaohua
 * @date 2018/4/9${time}.
 */
public class ImportErrorVO<T> {

    private List<T> errorList;
    private boolean isFinish;

    public List<T> getErrorList() {
        return errorList;
    }

    public List<T> getErrorList(Class<T> clazz){
        List<T> list = new ArrayList<>();
        if(errorList!=null){
            for (Object t : errorList) {
                if(t instanceof JSONObject){
                    list.add(((JSONObject)t).toJavaObject(clazz));
                }else{
                    String json = JSON.toJSONString(t);
                    list.add(JSON.parseObject(json,clazz));
                }
            }
        }
        return list;
    }

    public void setErrorList(List<T> errorList) {
        this.errorList = errorList;
    }

    public boolean isFinish() {
        return isFinish;
    }

    public void setFinish(boolean finish) {
        isFinish = finish;
    }
}